$msg = $_POST['msg'];
$sql = "INSERT INTO comments (message,created_at,imgID) VALUES ('$msg',CURRENT_TIMESTAMP,imgID)";
$qry = mysql_query($sql);
$lastid = mysql_insert_id();

$sqlData = "SELECT * FROM c.comments WHERE c.imgID = '$lastid'";
$qryData = mysql_query($sqlData);
$rsData = mysql_fetch_array($qryData);

$sqlData2 = "SELECT users.username FROM comments JOIN users ON (comments.userid = users.userid)";
$qryData2 = mysql_query($sqlData2);
$rsData2 = mysql_fetch_array($qryData2);

echo '<div class="list">
    <div class="icon">
        <img src="/uploads/jquerysamples/avatar2.jpg" /> <!-- since its sample only we default the avatar -->
    </div>
    <div class="message">
        <span class="name">'.$rsData2['users.username'].'</span>'.$rsData['message'].'<br />
        <span class="date">'.$rsData['created_at'].'</span>
    </div>
</div>';

